<template>
  <div>
      <el-date-picker
          v-model="formData.start"
          type="datetime"
          placeholder="选择日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="'00:00:00'"
      >
      </el-date-picker>
      -
      <el-date-picker
          v-model="formData.end"
          type="datetime"
          placeholder="选择日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="'23:59:59'"
      >
      </el-date-picker>
        <el-button
            icon="el-icon-search"
            type="primary"
            style="margin-left: 30px"
            @click="serach(formData.start,formData.end)">搜索</el-button>
        <el-table
            :data="orderData"
            style="width: 100%;"
            border
            :header-cell-style="{ background: '#00abbe', color: '#fff' }">
          <el-table-column prop="orderid" label="交易编号" align="center"></el-table-column>
          <el-table-column align="center" prop="ordername" label="用户支付账号"></el-table-column>
          <el-table-column align="center" prop="orderprice" label="订单金额"></el-table-column>
          <el-table-column align="center" prop="orderdate" label="交易时间"></el-table-column>
          <el-table-column align="center" prop="orderpaytype" label="交易类型"></el-table-column>
        </el-table>
      <div>
        <el-button icon="el-icon-shopping-cart-2" round @click="linktogoods" type="warning">查看商品</el-button>
        <el-button icon="el-icon-house" round @click="linktohello" type="info">返回主页</el-button>
      </div>
  </div>
</template>

<script>
import Qs from "qs";

export default {
  name: "Ordercheck",
  data() {
    return{
      searchname:'',
      orderData:[],
      formData: {
        start:'',//开始日期
        end:''//结束日期
      }
    }
  },
  created(){
    this.axios.post('/api/orderlist',Qs.stringify({userid:'123456789'}))
        .then(res => {
          this.orderData = res.data
          window.console.log(this.orderData)
        })
        .catch(function (error){
          console.log(error)
        })
  },
  methods:{
    //查看商品页面
    linktogoods(){
      this.$router.push('/fornt')
    },
    //根据时间搜索订单记录
    serach(start,end){
      this.$axios.post('/api/ordersearch',Qs.stringify({userid:'123456789',startdate:start,enddate:end}))
          .then(res => {
            this.orderData = res.data
          })
          .catch(function (error){
            console.log(error)
          })
    },
    //返回主页
    linktohello() {
      this.$router.push('/')
    }
  }
}
</script>

<style scoped>

</style>